/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app_99;

import java.util.ArrayList;

/**
 *
 * @author
 */
public class Session {

    private String establishment = "";
    private java.sql.Date date = null;
    private int current = 0;
    private int total = 0;
    private int peek = 0;
    private double average = 0;
    private int max = 300; //Hard coded for this assignment
    private double revenue = 0;
    private double avgRev = 0;
    private double currentCap = 0;
    private ArrayList<Integer> log = new ArrayList<Integer>();
    private boolean alreadyInDB = false;

    //Constructor
    public Session() {

    }

    public String getEstablishment() {
        return establishment;
    }

    public void setEstablishment(String establishment) {
        this.establishment = establishment;
    }

    public java.sql.Date getDate() {
        return date;
    }

    public void setDate(java.sql.Date date) {
        this.date = date;
    }

    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
        this.current = total;
        recalc();
    }

    public int getPeek() {
        return peek;
    }

    public void setPeek(int peek) {
        this.peek = peek;
    }

    public double getAverage() {
        return average;
    }

    public void setAverage(double average) {
        this.average = average;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public double getRevenue() {
        return revenue;
    }

    public void setRevenue(double revenue) {
        this.revenue = revenue;
    }

    public double getAvgRev() {
        return avgRev;
    }

    public double getCurrentCap() {
        return currentCap;
    }

    public void setCurrentCap(double currentCap) {
        this.currentCap = currentCap;
    }

    public void setAvgRev(double avgRev) {
        this.avgRev = avgRev;
    }

    public boolean isAlreadyInDB() {
        return alreadyInDB;
    }

    public void setAlreadyInDB(boolean alreadyInDB) {
        this.alreadyInDB = alreadyInDB;
    }

    public void increment() {
        total++;
        current++;
        recalc();

        // Recalculate the average revenue;
        setAvgRev(revenue / total);
    }

    public void decrement() {
        current--;
        setTotal(current);
        recalc();
    }

    private void recalc() {
        log.add(current);
        double sum = 0;
        double count = log.size();
        for (int i = 0; i < count; i++) {
            sum += log.get(i);
        }

        average = sum / count;

        if (current > peek) {
            peek = current;
        }
        
        setCurrentCap((double)current / (double)max);
    }
}
